package com.xianda.spring.controller;

import com.xianda.spring.base.BaseDirectService;
import com.xianda.spring.base.factory.BaseDirectServiceFactory;
import com.xianda.spring.base.param.BaseRequest;
import com.xianda.spring.base.param.BaseResponse;
import com.xianda.spring.config.ConfigProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Map;

@Controller
public class IndexController {

	@Autowired
	private ConfigProperties configProperties;

	@Autowired
	private BaseDirectServiceFactory directServiceFactory;

	@RequestMapping("/index")
	public String index(Map<String, Object> map) {
		map.put("hello", configProperties.getName());
		return "index";
	}

	@RequestMapping("/home")
	public String indexs(Map<String, Object> map) {
		map.put("hello", configProperties.getName());
		return "/home/home";
	}

	@RequestMapping("/param/{service}")
	public String param(@PathVariable String service, BaseRequest request) {
		System.out.println(service);
		BaseDirectService bs = directServiceFactory.getBaseDirectService(service);
		BaseResponse response = bs.doExecute(request);
		return "/home/home";
	}
}